{include file="public/header" /}

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <select name="cate">
                                <option value="">分类</option>
                                {foreach $cate as $v}
                                <option value="{$v.id}" {if !empty(input('get.cate')) &&
                                    input('get.cate')==$v.id}selected{/if}>{$v.name}</option>
                                {/foreach}
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <select name="status">
                                <option value="">是否推荐</option>
                                <option value="1" {if !empty(input('get.isBest')) &&
                                    input('get.isBest')==1}selected{/if}>推荐</option>
                                <option value="2" {if !empty(input('get.isBest')) &&
                                    input('get.isBest')==2}selected{/if}>正常</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <select name="status">
                                <option value="">是否热卖</option>
                                <option value="1" {if !empty(input('get.isHot')) && input('get.isHot')==1}selected{/if}>
                                </option>
                                热卖</option>
                                <option value="2" {if !empty(input('get.isHot')) && input('get.isHot')==2}selected{/if}>
                                    正常</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <select name="status">
                                <option value="">是否新品</option>
                                <option value="1" {if !empty(input('get.isNew')) && input('get.isNew')==1}selected{/if}>
                                    新品</option>
                                <option value="2" {if !empty(input('get.isNew')) && input('get.isNew')==2}selected{/if}>
                                    正常</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="title" placeholder="商品名称|商品编号" value="{:input('get.title')}"
                                autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="sreach">搜索</button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    <div class="layui-form-item layui-inline">
                        <select name="mycate">
                            <option value="">选择需要导入的平台分类</option>
                            {foreach $mycate as $v}
                            <option value="{$v.id}" {if !empty(input('get.mycate')) &&
                                input('get.mycate')==$v.id}selected{/if}>{$v.name}</option>
                            {/foreach}
                        </select>
                    </div>
                    <button class="layui-btn layui-btn-normal"
                        onclick="daorus()">导入(导入商品库存默认999,如有需求请手动更改)</button>&nbsp;
                    共有数据：<strong id="count">{:count($list)}</strong> 条
                </div>
                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-table layui-form">
                        <thead>
                            <tr>
                                <th>
                                    <input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose">
                                </th>
                                <th>ID</th>
                                <th>商品名称</th>
                                <th>商品图册</th>
                                <th>规格列表(如需更改规格，请在导入后在商品列表编辑)</th>
                                <th>所属分类</th>
                                <th>是否推荐</th>
                                <th>是否热销</th>
                                <th>是否新品</th>
                            </tr>
                        </thead>
                        <tbody class="role_list">
                            {foreach $list as $v}
                            {if $v.ishave == 2}
                            <tr>
                                <td>
                                    <input type="checkbox" name="checkboxcc[{$v.id}]" value="{$v.id}" lay-skin="primary"
                                        lay-filter="itemChoose" {if $v.ishave!=2}disabled{/if}>
                                </td>
                                <td>{$v.id|default=''}</td>
                                <td>{$v.title|default=''}</td>
                                <td>
                                    <div id="layer-photos" class="layer-photos">
                                        {foreach $v.images as $vs}
                                        <img layer-pid="" layer-src="{$vs|default=''}" src="{$vs|default=''}"
                                            alt="{$title|default=''}">
                                        {/foreach}
                                    </div>
                                </td>
                                <td>
                                    {foreach $v.goodspec as $f}
                                    {$f.name}(￥{$f.price})<br />
                                    {/foreach}

                                </td>
                                <td>{$v.catename|default=''}</td>
                                <td>
                                    {if !empty($v.isBest) && $v.isBest == 1}推荐{else/}正常{/if}
                                </td>
                                <td>
                                    {if !empty($v.isHot) && $v.isHot == 1}热卖{else/}正常{/if}
                                </td>
                                <td>
                                    {if !empty($v.isNew) && $v.isNew == 1}新品{else/}正常{/if}
                                </td>

                            </tr>
                            {/if}
                            {/foreach}

                        </tbody>
                    </table>
                </div>

            </div>
        </div>
    </div>
</div>
</body>
<script>
    function daorus() {
        var check_arr = [];
        var cate = $("select[name='mycate']").val();
        if (!cate) {
            layer.msg('请选择导入分类', { icon: 2, time: 1000 });
            return false;
        }
        $.each($('.role_list input:checkbox:checked'), function () {
            check_arr.push($(this).val());
        });
        var leimu = '';
        if (check_arr.length > 0) {
            layer.open({
                title: '确定需要导入到该分类吗',
                content: '',
                btn: ['导入', '取消'],
                yes: function () {
                    $.ajax({
                        type: 'post',
                        url: '/shop/xpgoodslist_edit',
                        data: { id: check_arr, cate: cate },
                        success: function (res) {
                            if (res.code == 0) {
                                layer.msg(res.msg, { icon: 6, time: 1000 }, function () {
                                    // 获得frame索引
                                    location.reload();
                                });
                            } else {
                                layer.msg(res.msg, { icon: 2, time: 1000 }, function () {
                                    // 获得frame索引
                                    location.reload();
                                });
                                return false;
                            }
                        }
                    });
                }
            });
        } else {
            layer.msg('请选中商品', { icon: 2, time: 1000 });
            return false;
        }
    }
    layui.use(['form', 'element', 'jquery'], function () {
        var form = layui.form,
            element = layui.element,
            $ = layui.jquery;
        //全选功能   
        form.on('checkbox(allChoose)', function (data) {
            var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
            child.each(function (index, item) {
                item.checked = data.elem.checked;
            });
            form.render('checkbox');
        });
        //全选和部分选中时候,表头全选按钮的样式变化
        form.on('checkbox(itemChoose)', function (data) {
            var sib = $(data.elem).parents('table').find('tbody input[type="checkbox"]:checked').length;
            var total = $(data.elem).parents('table').find('tbody input[type="checkbox"]').length;
            if (sib == total) {
                $(data.elem).parents('table').find('thead input[type="checkbox"]').prop("checked", true);
                form.render();
            } else {
                $(data.elem).parents('table').find('thead input[type="checkbox"]').prop("checked",
                    false);
                form.render();
            }
        });
    });
</script>
<script>
    layer.photos({
        photos: '#layer-photos'
        , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
    });
</script>
{include file="public/footer"}